Skip to content

Make typealias_unfold transitive#5201

Merged
SeanTAllen merged 1 commit intomainfrom
fix-issue-5195-transitive-typealias-unfold
Apr 9, 2026
Merged

Make typealias_unfold transitive#5201
SeanTAllen merged 1 commit intomainfrom
fix-issue-5195-transitive-typealias-unfold

Conversation

@SeanTAllen
Copy link
Copy Markdown
Member

@SeanTAllen SeanTAllen commented Apr 9, 2026

PR #5145 stopped expanding type aliases at name resolution, leaving TK_TYPEALIASREF in the AST. The on-demand typealias_unfold helper unfolded exactly one level, so chained aliases (type A is B; type B is (U64, U64)) returned another alias and any caller that inspected the head of the result crashed or miscompiled. PRs #5193 and #5196 fixed two crash sites with per-site unfolds; #5195 (this PR) makes the helper transitive at the source so the bug class is closed structurally.

The helper now guarantees its result has a non-alias head. Termination is bounded by the alias chain length, which is finite because pass/names.c rejects cyclic alias defs via AST_FLAG_RECURSE_1 before any TK_TYPEALIASREF is emitted. A coupling comment in names.c documents this dependency for future maintainers.

Also fixes a related #5145 regression in gentrace_needed's TRACE_TUPLE branch (iterated tuple element children without unfolding the operand types; crashed both single-level and chained tuple aliases; found during review via an asymmetric argument/parameter pattern) and removes the now-stale "known gap" comment from trace_dynamic_tuple (added in #5196 when the chained-alias case was untestable).

New full-program-tests cover the affected codegen and expression paths. Each asserts a specific exit code so it catches both assertion crashes and silent miscompilation.

Closes #5195

@ponylang-main ponylang-main added the discuss during sync Should be discussed during an upcoming sync label Apr 9, 2026
@SeanTAllen
Copy link
Copy Markdown
Member Author

SeanTAllen commented Apr 9, 2026

Review surfaced two pre-existing leaks of the same class (function allocates a tree via typealias_unfold, may return a pointer into it, never freed). Both pre-existing from #5145, not introduced here, filed as separate issues: #5199 (find_infer_type in operator.c) and #5200 (find_possible_fun_defs in lambda.c). Isomorphic — worth fixing together.

@SeanTAllen SeanTAllen force-pushed the fix-issue-5195-transitive-typealias-unfold branch from addb505 to dcfdd31 Compare April 9, 2026 19:52
PR #5145 stopped expanding type aliases during name resolution, leaving
them as TK_TYPEALIASREF in the AST. Every site that needs the underlying
concrete type calls typealias_unfold on demand. The helper unfolded
exactly one level, so chained aliases (`type A is B; type B is (U64,
U64)`) returned another TK_TYPEALIASREF and any caller that inspected
the head of the result crashed or miscompiled. PRs #5193 and #5196
fixed two crash sites with per-site unfolds, but the same bug class
kept surfacing elsewhere.

Make typealias_unfold transitive: if reify and apply_cap produce another
TK_TYPEALIASREF, recurse until the head is concrete. The helper now
guarantees its result has a non-alias head, so callers can rely on that
postcondition. Termination is bounded by the alias chain length, which
is finite because pass/names.c rejects cyclic alias defs via
AST_FLAG_RECURSE_1 before any TK_TYPEALIASREF is emitted. A coupling
comment in names.c documents this dependency for future maintainers.

Also fixes a related #5145 regression in gentrace_needed's TRACE_TUPLE
branch, which iterated tuple element children without unfolding the
operand types and crashed on both single-level and chained tuple
aliases (found during review via an asymmetric argument/parameter
pattern). And removes the now-stale "known gap" comment in
trace_dynamic_tuple's TRACE_TUPLE branch (added by #5196) since chained
aliases now resolve to a concrete TK_TUPLETYPE through the transitive
unfold.

The new full-program-tests cover the affected codegen and expression
paths at specific exit codes so they catch both assertion crashes and
silent miscompilation.

Closes #5195
@SeanTAllen SeanTAllen merged commit 51e5a4f into main Apr 9, 2026
20 checks passed
@SeanTAllen SeanTAllen deleted the fix-issue-5195-transitive-typealias-unfold branch April 9, 2026 22:50
@ponylang-main ponylang-main removed the discuss during sync Should be discussed during an upcoming sync label Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Audit typealias_unfold call sites for chained-alias handling

2 participants